﻿#pragma once

#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

class GraphEdge;

class GraphNode
{
public:
    GraphNode(int value);

public:
    // 从该节点出发到达的邻点
    vector<GraphNode*> nextNodes;
    // 从该节点出发的边
    vector<GraphEdge*> edges;
    int value;
    // 连入该点的边的个数
    int in;
    // 连出该点的边的个数
    int out;
};

class GraphEdge
{
public:
    GraphEdge(GraphNode* from, GraphNode* to, int weight);

public:
    GraphNode* from;
    GraphNode* to;
    int weight;
};

class Graph
{
public:
    Graph();
    ~Graph();

    /**
     * 根据路径生成图
     * @param matrix 路径的二维数组的指针
     * @param rowCount 二维数组的行数
     * @param colCount 二维数组的列数
     * @param isDigraph 是否是有向图？
     * @return 图结构
     */
    static Graph* generate(int** matrix, int rowCount, int colCount, bool isDigraph);

public:
    unordered_map<int, GraphNode*> nodes;
    unordered_set<GraphEdge*> edges;
};